package com.ruoyi.qiuyue.controller;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.DictUtils;
import com.ruoyi.qiuyue.common.MusicConstat;
import com.ruoyi.system.domain.SysConfig;
import com.ruoyi.system.service.ISysConfigService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.qiuyue.domain.MusicSong;
import com.ruoyi.qiuyue.service.IMusicSongService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 音乐管理Controller
 * 
 * @author ruoyi
 * @date 2024-05-21
 */
@RestController
@RequestMapping("/music/song")
public class MusicSongController extends BaseController
{
    @Autowired
    private IMusicSongService musicSongService;
    @Autowired
    private ISysConfigService configService;

    /**
     * 查询音乐分类
     */
    @GetMapping("/type/list")
    public AjaxResult  typeList() {
        String types = configService.selectConfigByKey(MusicConstat.SONG_TYPE_KEY);
        String[] typeList = types.split(" ");
        Map<String,List > data = new HashMap<>();
        data.put("typeList", Arrays.asList(typeList));
        return AjaxResult.success().put("data",data);
    }
    /**
     * 查询音乐管理列表
     */
    @PreAuthorize("@ss.hasPermi('music:song:list')")
    @GetMapping("/list")
    public TableDataInfo list(MusicSong musicSong)
    {
        startPage();
        List<MusicSong> list = musicSongService.selectMusicSongList(musicSong);
        return getDataTable(list);
    }

    /**
     * 导出音乐管理列表
     */
    @PreAuthorize("@ss.hasPermi('music:song:export')")
    @Log(title = "音乐管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MusicSong musicSong)
    {
        List<MusicSong> list = musicSongService.selectMusicSongList(musicSong);
        ExcelUtil<MusicSong> util = new ExcelUtil<MusicSong>(MusicSong.class);
        util.exportExcel(response, list, "音乐管理数据");
    }

    /**
     * 获取音乐管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('music:song:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(musicSongService.selectMusicSongById(id));
    }

    /**
     * 新增音乐管理
     */
    @PreAuthorize("@ss.hasPermi('music:song:add')")
    @Log(title = "音乐管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MusicSong musicSong)
    {
        return toAjax(musicSongService.insertMusicSong(musicSong));
    }

    /**
     * 修改音乐管理
     */
    @PreAuthorize("@ss.hasPermi('music:song:edit')")
    @Log(title = "音乐管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MusicSong musicSong)
    {
        return toAjax(musicSongService.updateMusicSong(musicSong));
    }

    /**
     * 删除音乐管理
     */
    @PreAuthorize("@ss.hasPermi('music:song:remove')")
    @Log(title = "音乐管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(musicSongService.deleteMusicSongByIds(ids));
    }
}
